package tech.aistar.Conteoller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import tech.aistar.mapper.ItemexperienceMapper;
import tech.aistar.mapper.WantjobMapper;
import tech.aistar.model.entity.Customer;
import tech.aistar.model.entity.Itemexperience;
import tech.aistar.model.entity.Resume;
import tech.aistar.model.entity.Wantjob;
import tech.aistar.service.IResumeService;

import java.util.List;

@Controller
@RequestMapping("personal")
public class   PersonalController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private IResumeService iResumeService;

    @Autowired
    private WantjobMapper wantjobMapper;

    @Autowired
    private ItemexperienceMapper itemexperienceMapper;

    @GetMapping("p")
    public String personall(HttpServletRequest req){

        if(redisTemplate.hasKey("customer")){
            Customer customer= (Customer) redisTemplate.opsForValue().get("customer");
            Wantjob wantjob=wantjobMapper.getWantjobByWantjobId(iResumeService.findResumeByCustomerId(customer.getId()).getWantjobId());
            Resume r = iResumeService.findResumeByCustomerId(customer.getId());
            List<Itemexperience> list=itemexperienceMapper.getItemExperByResumeId(r.getId());
            req.setAttribute("headImg",customer.getHeadImg());
            req.setAttribute("customerId",customer.getId());
            req.setAttribute("items",list);
            req.setAttribute("wantJob",wantjob);
            req.setAttribute("customer",customer);
            req.setAttribute("resume",iResumeService.findResumeByCustomerId(customer.getId()));
        }
        return "personal/Personal";
    }


}
